Creating and Drawing Curves
You can create and draw curve shapes with QuickDraw GX the same way you create and draw points and lines. Typically, you first define a curve geometry, which is encapsulated in agxCurve
structure:
struct gxCurve { struct gxPoint first; struct gxPoint control; struct gxPoint last; };Thefirst
andlast
fields determine the start point and the end point of the curve. The point specified in thecontrol
field lies off the curve and determines the tangents of the curve. (The off-curve control point could actually be on the curve--that is, directly between the first and last points--in which case the curve is a straight line.)Once you've defined a curve geometry, you can create a curve shape using the
GXNewCurve
function and draw it using theGXDrawShape
function, as shown in Listing 2-9.Listing 2-9 Creating a curve shape
void CreateCurve(void) { gxShape aCurveShape; static gxCurve aCurveGeometry = {ff(50), ff(50), /* on */ ff(100), ff(150), /* off */ ff(200), ff(50)}; /* on */ aCurveShape = GXNewCurve(&aCurveGeometry); GXDrawShape(aCurveShape); GXDisposeShape(aCurveShape); }Figure 2-22 shows the curve shape geometry, which includes the first and last points, the off-curve control point, and the tangents implied by these geometric points. This figure also shows the curve as drawn. It is drawn as a hairline (one-pixel wide) with the open-frame shape fill, which reflects the default values for curve shapes.
You could draw the same curve without creating a curve shape by calling the
GXDrawCurve
function:
GXDrawCurve(&aCurveGeometry);You could also create the curve shape using theGXNewShape
function described in Inside Macintosh: QuickDraw GX Objects or theGXNewShapeVector
function described on page 2-109.Curves have a direction that depends on the order of the points in the geometry. For example, you could reverse the direction of the curve in Figure 2-22 by reversing the order of the points in the geometry definition from Listing 2-9:
static gxCurve aCurveGeometry = {ff(200), ff(50), /* on curve */ ff(100), ff(150), /* off curve */ ff(50), ff(50)}; /* on curve */Changing the direction of this curve would not change its appearance. However, curve direction can affect the appearance of a curve when you apply certain stylistic variations, such as dashing, to the curve. The next chapter, "Geometric Styles," discusses these stylistic variations. Also, when a curve is part of a path shape, the direction of the curve can affect the way the path is drawn. See "Creating and Drawing Paths" beginning on page 2-55 for examples of how the direction of a curve can affect drawing.For more information about curve shapes, see "Curve Shapes" on page 2-18 and "The Curve Structure" on page 2-105. For information about the functions you can use to create and draw curves, see the description of the
GXNewCurve
function on page 2-113 and theGXDrawCurve
function on page 2-159.
Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help